from selenium.webdriver.common.by import By

from common.utils import Driver
from common.utils import ScreenShot


class BlogNotLogined:
    def __init__(self):
        # 博客首页
        self.index_url = "http://8.137.19.140:9090/blog_list.html"
        # 博客详情页
        self.detail_url = "http://8.137.19.140:9090/blog_detail.html?blogId=22549"
        # 博客编辑页
        self.edit_url = "http://8.137.19.140:9090/blog_edit.html"
        # 博客登录页
        self.login_url = "http://8.137.19.140:9090/blog_login.html"

    # 用户未登录进入首页，自动跳转登录页
    def index_not_logined(self):
        Driver.get(self.index_url)
        ScreenShot()
        # 检查当前页面，是否登录页面元素
        actual = Driver.find_element(By.XPATH, "/html/body/div[2]/div/h3").text
        assert "登陆" == actual and "博客登陆页" == Driver.title

    # 用户未登录进入博客详情页，自动跳转登录页
    def detail_not_logined(self):
        Driver.get(self.detail_url)
        ScreenShot()
        # 检查当前页面，是否登录页面元素
        actual = Driver.find_element(By.XPATH, "/html/body/div[2]/div/h3").text
        assert "登陆" == actual and "博客登陆页" == Driver.title

    # 用户未登录进入详情编辑页，自动跳转登录页
    def edit_not_logined(self):
        Driver.get(self.edit_url)
        ScreenShot()
        # 检查当前页面，是否登录页面元素
        actual = Driver.find_element(By.XPATH, "/html/body/div[2]/div/h3").text
        assert "登陆" == actual and "博客登陆页" == Driver.title

    def test_case(self):
        Driver.implicitly_wait(10)
        self.index_not_logined()
        self.detail_not_logined()
        self.edit_not_logined()
